#!/bin/bash
instanceCount=30
parameter="frozen"
path="../../../../../../../data/task5/instance.dat.sol.annealing.$parameter"
if [ -f $path ] ; then
    lines=`cat $path | wc -l`
    parameterCount=`echo $lines/$instanceCount | bc`
else
    echo "Soubor ${path##*/} neexistuje!!!"
fi

for (( c=1; c<=parameterCount; c++ )); do

    firstLine=`echo "1 + ($c-1)*10" | bc`
    lastLine=`echo "$c*10" | bc`
    singleParameterResults=`sed -n "$firstLine,$lastLine p" $path`
    times=`echo "$singleParameterResults" | cut -d " " -f2`
    fault=`echo "$singleParameterResults" | cut -d " " -f4`
    sum=0
    count=0

    for i in $times; do
      sum=`echo $i+$sum | bc`
      count=`echo "$count + 1" | bc`
    done

    averageTime=`echo "scale=4;$sum / $count" | bc`

    sum=0
    count=0
    for i in $fault; do
      sum=`echo $i+$sum | bc`
      count=`echo "$count + 1" | bc`
    done

    averageFault=`echo "$sum / $count" | bc`

    echo "Soubor ${path##*/}, param cislo $c:"
    echo "Prumerny cas: $averageTime ms"
    echo "Prumerna relativni chyba: $averageFault"
    echo

done